home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / unix / mp14tar.z / mp14tar / mpack / dospk.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  4KB  |  163 lines

  1. /* (C) Copyright 1993 by John G. Myers
  2.  * All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without
  6.  * fee, provided that the above copyright notice appear in all copies
  7.  * and that both that copyright notice and this permission notice
  8.  * appear in supporting documentation, and that the name of John G.
  9.  * Myers not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  John G. Myers makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as
  13.  * is" without express or implied warranty.
  14.  *
  15.  * JOHN G. MYERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL JOHN G. MYERS BE LIABLE FOR ANY SPECIAL,
  18.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21.  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <errno.h>
  28. #include "version.h"
  29. #include "xmalloc.h"
  30.  
  31. #define MAXADDRESS 100
  32.  
  33. extern int optind;
  34. extern char *optarg;
  35.  
  36. main(argc, argv)
  37. int argc;
  38. char **argv;
  39. {
  40.     int opt;
  41.     char *fname = 0;
  42.     char *subject = 0;
  43.     char *descfname = 0;
  44.     long maxsize = 0;
  45.     char *outfname = 0;
  46.     char *ctype = 0;
  47.     char *headers = 0;
  48.     int i;
  49.     char *p;
  50.     char sbuf[1024];
  51.     char fnamebuf[4096];
  52.     int part;
  53.     FILE *infile;
  54.     FILE *descfile = 0;
  55.  
  56.     if ((p = getenv("SPLITSIZE")) && *p >= '0' && *p <= '9') {
  57.     maxsize = atoi(p);
  58.     }
  59.  
  60.     while ((opt = getopt(argc, argv, "s:d:m:c:o:n:")) != EOF) {
  61.     switch (opt) {
  62.     case 's':
  63.         subject = optarg;
  64.         break;
  65.  
  66.     case 'd':
  67.         descfname = optarg;
  68.         break;
  69.  
  70.     case 'm':
  71.         maxsize = atol(optarg);
  72.         break;
  73.  
  74.     case 'c':
  75.         ctype = optarg;
  76.         break;
  77.  
  78.     case 'o':
  79.         outfname = optarg;
  80.         break;
  81.  
  82.     default:
  83.         usage();
  84.  
  85.     }
  86.     }
  87.  
  88.     if (ctype) {
  89.     if (!cistrncmp(ctype, "text/", 5)) {
  90.         fprintf(stderr, "This program is not appropriate for encoding textual data\n");
  91.         exit(1);
  92.     }
  93.     if (cistrncmp(ctype, "application/", 12) && cistrncmp(ctype, "audio/", 6) &&
  94.         cistrncmp(ctype, "image/", 6) && cistrncmp(ctype, "video/", 6)) {
  95.         fprintf(stderr, "Content type must be subtype of application, audio, image, or video\n");
  96.         exit(1);
  97.     }
  98.     }
  99.  
  100.     if (!outfname) {
  101.     fprintf(stderr, "The -o switch is required\n");
  102.     usage();
  103.     }
  104.  
  105.     if (optind == argc) {
  106.     fprintf(stderr, "An input file must be specified\n");
  107.     usage();
  108.     }
  109.     fname = argv[optind++];
  110.     for (p = fname; *p; p++) {
  111.     if (isupper(*p)) *p = tolower(*p);
  112.     }
  113.  
  114.     /* Must have -o */
  115.     if (optind != argc) {
  116.     fprintf(stderr, "Too many arguments\n");
  117.     usage();
  118.     }
  119.  
  120.     if (!subject) {
  121.     fputs("Subject: ", stdout);
  122.     fflush(stdout);
  123.     if (!fgets(sbuf, sizeof(sbuf), stdin)) {
  124.         fprintf(stderr, "A subject is required\n");
  125.         usage();
  126.     }
  127.     if (p = strchr(sbuf, '\n')) *p = '\0';
  128.     subject = sbuf;
  129.     }    
  130.  
  131.     infile = fopen(fname, "rb");
  132.     if (!infile) {
  133.     os_perror(fname);
  134.     exit(1);
  135.     }
  136.  
  137.     if (descfname) {
  138.     descfile = fopen(descfname, "r");
  139.     if (!descfile) {
  140.         os_perror(descfname);
  141.         exit(1);
  142.     }
  143.     }
  144.  
  145.     if (encode(infile, (FILE *)0, fname, descfile, subject, headers,
  146.            maxsize, ctype, outfname)) exit(1);
  147.  
  148.     exit(0);
  149. }
  150.  
  151. usage()
  152. {
  153.     fprintf(stderr, "mpack version %s\n", MPACK_VERSION);
  154.     fprintf(stderr, 
  155. "usage: mpack [-s subj] [-d file] [-m maxsize] [-c content-type] -o output file\n");
  156.     exit(1);
  157. }
  158.  
  159. warn()
  160. {
  161.     abort();
  162. }
  163.